﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace LungSoundWizard.ViewModel
{
    public class RecordNewViewModel : WizardViewModelBase
    {
        public override string Title
        {
            get { return "Record lung sound"; }
        }

        RelayCommand _recordCommand;
        public ICommand RecordCommand
        {
            get
            {
                if (_recordCommand == null)
                {
                    _recordCommand = new RelayCommand(p => this.StartStopRecord());
                }
                return _recordCommand;
            }
        }

        bool _isRunning;
        public bool IsRunning
        {
            get { return _isRunning; }
            set { SetProperty(ref _isRunning, value); }
        }

        bool _isRecording;
        public bool IsRecording
        {
            get { return _isRecording; }
            set 
            { 
                SetProperty(ref _isRecording, value);

                if (IsRecording)
                {
                    RecordText = "Stop Recording";
                }
                else
                {
                    RecordText = "Record";
                }
            }
        }

        string _filePath;
        public string FilePath
        {
            get { return _filePath; }
            set { SetProperty(ref _filePath, value); }
        }

        string _recordText = "Record";
        public string RecordText
        {
            get { return _recordText; }
            set { SetProperty(ref _recordText, value); }
        }

        OpenExistingViewModel _openExistingVM;

        public RecordNewViewModel(OpenExistingViewModel openExistingVM)
        {
            _openExistingVM = openExistingVM;
        }

        public override void OnShow()
        {
            IsRunning = true;
        }

        public override void OnHide()
        {
            if (IsRecording)
            {
                IsRecording = false;
            }

            IsRunning = false;
        }

        void StartStopRecord()
        {
            IsRecording = !IsRecording;

            if (IsRecording == false && FilePath != null)
            {
                NextPage = _openExistingVM;
                _openExistingVM.FilePath = FilePath;
                _openExistingVM.IsProvidedPath = true;
                OnRequestNextPage();
            }
        }
    }
}
